﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebUI.Areas.Admin.Models
{
    public class ServerUtil
    {

        /// <summary>  
        ///获取操作系统版本  
        /// </summary>  
        /// <returns></returns>  
        public static string GetSystemVersion()
        {
            return Environment.OSVersion.ToString();
        }

        /// <summary>  
        /// 服务器计算机名称  
        /// </summary>  
        /// <returns></returns>  
        public static string GetServerName()
        {
            return HttpContext.Current.Server.MachineName;//服务器名称  
        }

        /// <summary>  
        /// 服务器IP地址    
        /// </summary>  
        /// <returns></returns>  
        public static string GetServerIp()
        {
            return HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];
        }

        /// <summary>  
        /// 服务器域名    
        /// </summary>  
        /// <returns></returns>  
        public static string GetDomainName()
        {
            return HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
        }

        /// <summary>  
        /// /.NET解释引擎版本  
        /// </summary>  
        /// <returns></returns>  
        public static string GetDotNetVersion()
        {
            return ".NET CLR" + Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build + "." + Environment.Version.Revision;
        }

        /// <summary>  
        /// IIS版本  
        /// </summary>  
        /// <returns></returns>  
        public static string GetServerSoftware()
        {
            return HttpContext.Current.Request.ServerVariables["SERVER_SOFTWARE"];
        }

        /// <summary>  
        /// HTTP访问端口    
        /// </summary>  
        /// <returns></returns>  
        public static string GetServerPort()
        {
            return HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
        }

        /// <summary>  
        /// 虚拟目录的绝对路径    
        /// </summary>  
        /// <returns></returns>  
        public static string GetApplRhysicalPath()
        {
            return HttpContext.Current.Request.ServerVariables["APPL_RHYSICAL_PATH"];
        }

        /// <summary>  
        /// 执行文件的绝对路径    
        /// </summary>  
        /// <returns></returns>  
        public static string GetPathTranslated()
        {
            return HttpContext.Current.Request.ServerVariables["PATH_TRANSLATED"];
        }

        /// <summary>  
        /// 虚拟目录Session总数   
        /// </summary>  
        /// <returns></returns>  
        public static string GetSessionCount()
        {
            return HttpContext.Current.Session.Contents.Count.ToString();
        }

        /// <summary>  
        /// 虚拟目录Application总数    
        /// </summary>  
        /// <returns></returns>  
        public static string GetApplicationCount()
        {
            return HttpContext.Current.Application.Contents.Count.ToString();
        }

        /// <summary>  
        /// 服务器区域语言   
        /// </summary>  
        /// <returns></returns>  
        public static string GetAcceptLanguage()
        {
            return HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];//服务器区域语言    
        }

        /// <summary>  
        /// CPU个数      
        /// </summary>  
        /// <returns></returns>  
        public static string GetCpuCount()
        {
            return Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");//CPU个数      
        }

        /// <summary>  
        /// CPU类型   
        /// </summary>  
        /// <returns></returns>  
        public static string GetCpuIdentifier()
        {
            return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");//CPU个数      
        }

        /// <summary>  
        /// 系统所在目录   
        /// </summary>  
        /// <returns></returns>  
        public static string GetSystemPath()
        {
            return Environment.SystemDirectory;//
        }
    }
}